#pragma once

#include "state.hpp"

#include <lua.hpp>

#include <concepts>
#include <filesystem>
#include <functional>
#include <optional>
#include <string>
#include <type_traits>

namespace division_engine::lua
{
class LuaManager
{
public:
    LuaManager() noexcept;
    ~LuaManager();

    LuaManager(LuaManager&) = delete;
    LuaManager(LuaManager&&) = delete;
    LuaManager& operator=(const LuaManager&) = delete;
    LuaManager& operator=(LuaManager&&) = delete;

    State& state() { return _state; }

    static LuaManager with_search_script_path(const std::filesystem::path& path);
    
    void set_watch_file(const std::filesystem::path& main_script_path);
    void update();

private:
    State _state;
    std::optional<std::filesystem::path> _main_script_path;
    std::filesystem::file_time_type _last_write_time;

    bool check_script_changes(const std::filesystem::path& script_path);
};
}